<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>品牌管理</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .container {
            margin-top: 20px;
        }
        .table th {
            background-color: #f8f9fa;
        }
        .btn-group .btn {
            margin-right: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-12">
                <h2 class="mb-4">品牌管理</h2>
                
                <!-- 成功消息 -->
                <div th:if="${success}" class="alert alert-success alert-dismissible fade show" role="alert">
                    <span th:text="${success}"></span>
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
                
                <!-- 错误消息 -->
                <div th:if="${error}" class="alert alert-danger alert-dismissible fade show" role="alert">
                    <span th:text="${error}"></span>
                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                </div>
                
                <!-- 操作按钮 -->
                <div class="mb-3">
                    <a href="/admin/brand/add" class="btn btn-primary">
                        <i class="bi bi-plus-circle"></i> 添加品牌
                    </a>
                </div>
                
                <!-- 品牌列表表格 -->
                <div class="table-responsive">
                    <table class="table table-striped table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>品牌名称</th>
                                <th>品牌图片</th>
                                <th>首字母</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr th:if="${#lists.isEmpty(brands)}">
                                <td colspan="5" class="text-center text-muted">暂无品牌数据</td>
                            </tr>
                            <tr th:each="brand : ${brands}">
                                <td th:text="${brand.id}"></td>
                                <td th:text="${brand.name}"></td>
                                <td>
                                    <span th:if="${brand.image}" th:text="${brand.image}"></span>
                                    <span th:unless="${brand.image}" class="text-muted">无图片</span>
                                </td>
                                <td th:text="${brand.firstChar}"></td>
                                <td>
                                    <div class="btn-group" role="group">
                                        <a th:href="@{/admin/brand/edit/{id}(id=${brand.id})}" class="btn btn-sm btn-outline-primary">
                                            编辑
                                        </a>
                                        <form th:action="@{/admin/brand/delete/{id}(id=${brand.id})}" method="post" style="display: inline;" 
                                              onsubmit="return confirm('确定要删除这个品牌吗？')">
                                            <button type="submit" class="btn btn-sm btn-outline-danger">
                                                删除
                                            </button>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>